<template>
  <div class="app-container">
    <!-- 查询表单-->
    <!--element-ui的 date-picker组件默认绑定的时间值是默认世界标准时间，和中国时间差8小时
          设置 value-format="yyyy-MM-dd HH:mm:ss" 改变绑定的值-->
    <div id="content">
      <i class="el-icon-menu">筛选</i>
      <p />
      <el-form :inline="true" :model="selectByAny" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input
            v-model="selectByAny.anyKeyWords"
            placeholder="请输入产品名称"
          ></el-input>
        </el-form-item>
     
       
        <el-button type="primary" icon="el-icon-search" @click="selectByRequirement()"
          >筛选</el-button
        >
        <el-button type="default" @click="resetData()">清空筛选条件</el-button>

        <el-form-item>
        
        <el-button type="info" plain @click="cancleSaveOrUpdate"
          >取消</el-button
        >
      </el-form-item>
      </el-form>
      <el-row>
        <el-col
          ><div class="grid-content bg-purple">
            <i class="el-icon-menu">回收站列表</i>
          </div></el-col
        >
        <el-col><div class="grid-content bg-purple-light"></div></el-col>
      </el-row>
      <p />
      <!--表格-->
      <el-table
        v-loading="listLoading"
        :data="list"
        @selection-change="handleSelectionChange"
        element-loading-text="数据加载中"
        border
        fit
        stripe
        highlight-current-row
        style="width: 100%"
      >
        <!--数据展示-->
         <!--数据展示-->
        <el-table-column type="selection" width="65"></el-table-column>
        <el-table-column prop="id" label="产品id" width="130" />
        <el-table-column prop="productName" label="产品名称" width="160"/>
        <el-table-column prop="issuer" label="发行机构（信息披露）" width="200" />
        <el-table-column prop="goldPrice" label="黄金价格（信息披露）" width="260" />
        <el-table-column prop="riskGrade" label="风险等级" width="160" />
        <el-table-column prop="monetary" label="购买金额（交易规则）" width="200" />
        <el-table-column prop="ageRange" label="年龄范围（交易规则）" width="200" />
        <el-table-column prop="receivePrice" label="领取金额（交易规则）" width="200" />
        <el-table-column prop="receiveDate" label="资金到账日期（交易规则）" width="200" />
        <el-table-column prop="tradeDate" label="交易日期（交易规则）" width="200" />

        <el-table-column prop="exchange" label="兑换实物金（交易规则）" width="200" />

        <el-table-column prop="introduction" label="利息规则（交易规则）" width="200" />

        <el-table-column prop="minMonetary" label="起购金额" width="200" />
       
       <el-table-column prop="type" label="数据源的API名称" width="200" />


        <el-table-column fixed="right" label="操作" width="300" align="center">
          <template slot-scope="scope">
              <el-button 
              type="primary" 
              size="mini" 
              icon="el-icon-edit"
              @click="recoverOneInRecycle(scope.row.id)">恢复</el-button
              >
            <el-button
              type="danger"
              size="mini"
              icon="el-icon-delete"
              @click="putIdInList(scope.row.id)"
              >彻底删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-col
          ><div class="grid-content bg-purple add">
              <el-button type="primary" @click="removeDataById" icon="el-icon-delete"
                >批量彻底删除</el-button
              >
          </div></el-col
        ><br/>

      <!-- 分页 -->
      <el-pagination
        :current-page="page"
        :page-size="limit"
        :total="total"
        background
        style="padding: 30px 0; text-align: center"
        layout="total, prev, pager, next, jumper"
        @current-change="selectByRequirement"
      />
    </div>
  </div>
</template>
<script>
//引入调用Teacher.js文件
import Teacher from "@/api/goldServer";

export default {
  //写核心代码位置
  // data:{
  // },
  data() {
    //定义变量和初始值
    return {
      listLoading: true, // 是否显示loading信息
      list: null, //查询之后接口返回集合
      page: 1, //当前页
      limit: 5, //每页记录数
      total: 0, //总记录数
      pageNum: 0,//当前页
      pageSize: 0,//总页数
      selectByAny: {
        activity_state:"",
        anyKeyWords: "",
        startTime: "",
        endTime: "",
      }, //条件封装对象
      checkList: [],
    };
  },
  created() {
    //页面渲染之前执行，一般调用methods定义的方法
    //调用
    this.selectAllToShow();
  },
  mounted() {
    this.listLoading = false;
  },
  methods: {
    //创建具体的方法，调用slideShow.js定义的方法
    //获取搜索回收站教师列表的方法,默认是第一页
    selectByRequirement(page = 1) {
      this.page = page;
      Teacher
        .getGoldRecycleListPage(this.page, this.selectByAny)
        .then((response) => {
          //请求成功
          //response接口返回的数据,教师、总数、当前页、总页数
          this.list = response.data.list;
          this.total = response.data.total;
          this.pageNum = response.data.pageNum;
          this.pageSize = response.data.pageSize;
        });
    },
      cancleSaveOrUpdate() {
      //判断当前产品状态,来决定跳转哪一个页面
     
        //回到已下架列表页面 路由跳转
        this.$router.push({ path: "/list/gold" });
     
    },
    //获取所有回收站教师的方法,默认是第一页
    selectAllToShow(page = 1) {
      this.page = page;
      Teacher
        .getGoldRecycleListPage(this.page, this.limit)
        .then((response) => {
          //请求成功
          //response接口返回的数据,教师、总数、当前页、总页数
          this.list = response.data.list;
          this.total = response.data.total;
          this.pageNum = response.data.pageNum;
          this.pageSize = response.data.pageSize;
        });
    },
    //恢复教师
    recoverOneInRecycle(id){
      this.id = id
      this.$confirm(
        "此操作将会恢复这条数据,您可以通过头条列表查看他 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          //点击确定，执行then方法
          //调用恢复的方法
      Teacher
        .recoverOne(id)
        .then((response) => {
            //恢复成功
            //提示信息
            this.$message({
              type: "success",
              message: "成功!",
            });
            //回到回收站列表页面
            this.selectByRequirement();
          });
        }).catch((e) => {
          this.$message({
            type: "info",
            message: "已取消删除!",
          });
        }); //点击取消，执行catch方法
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      //获取所有选中项的gh(工号)属性的值
      this.checkList = selection.map((item) => item.id);
    },
    resetData() {
      //清空搜索框的方法
      //表单输入项数据清空
      this.selectByAny = {};
      //查询所有回收站讲师数据
      this.selectByRequirement();
      this.$message({
        type: "success",
        message: "清空成功!",
      });
    },
    //将回收站教师ID放入list
    putIdInList(id){
      this.checkList.push(id),
      this.removeDataById()
    },
    //彻底删除回收站讲师的方法
    removeDataById() {
      this.$confirm(
        "此操作将会删除数据,您仍然可通过回收站找回 是否继续?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          //点击确定，执行then方法          
          //调用彻底删除的方法
         
          Teacher.deleteTotallyById(this.checkList).then((response) => {
            //彻底删除成功
            //提示信息
            this.$message({
              type: "success",
              message: "删除成功!",
               
            });

            this.checkList=[];
            //回到列表页面
            this.selectByRequirement();
          });
        })
        .catch((e) => {
          this.$message({
            type: "info",
            message: "已取消删除!",
          });
        }); //点击取消，执行catch方法
    },
  },
};
</script>
<style>
#content {
  width: 80%;
  margin: 0 auto;
}
.el-row .el-col-24 {
  width: 150px;
}
.el-col-24:nth-child(3),
.el-col-24:nth-child(4) {
  float: right;
}
</style>